﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using Microsoft.Office.Interop.Excel;
using System.Data;
using EagleSoft.ExtJS.Tree;

namespace Catering.Catering_Page.Caipin
{
    public partial class test : System.Web.UI.Page
    {
        public static string Jsons = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!Page.IsPostBack)
            {
                Jsons = "";
                switch (Request["type"].ToString())
                {
                    case "cailist":
                            
                        break;
                    case "yuanliao":
                        GetJsonType();
                        break;
                }

            }
        }

        private void GetJsonType()
        {
            string next = Request["next"];
            switch (Request["next"])
            {
                case "yuanliao":
                    Jsons = this.GetRawMaterialsList();
                    break;
                case "type_info":
                    Jsons = this.GetRawMaterialsInfoList();
                    break;
                case "item":
                    Jsons = this.GetRawMaterialList();
                    break;
            }
        }

        //获取原料大类列表
        public string GetRawMaterialsList()
        {
            TreeJSONHelper json = new TreeJSONHelper();
            System.Data.DataTable dt_RawMaterials = new Catering_Rules.T_RawMaterials().GetAllList().Tables[0];
            if (dt_RawMaterials != null && dt_RawMaterials.Rows.Count > 0)
            {
                for (int i = 0; i < dt_RawMaterials.Rows.Count; i++)
                {
                    json.AddItem("id", "D"+dt_RawMaterials.Rows[i]["id"].ToString());
                    json.AddItem("text", dt_RawMaterials.Rows[i]["TypeName"].ToString());
                    json.AddItem("self", "type");
                    json.AddItem("next", "type_info");
                    json.AddItem("leaf", "0");
                    json.ItemOk();
                }
            }
            return json.ToString();
        }

        //获取原料细类列表
        private string GetRawMaterialsInfoList()
        {
            string RMID = Request["id"];
            TreeJSONHelper json = new TreeJSONHelper();
            System.Data.DataTable dt_RawMaterialsInfo = new Catering_Rules.RawMaterialsInfo().GetList("RMID="+RMID).Tables[0];
            if (dt_RawMaterialsInfo != null && dt_RawMaterialsInfo.Rows.Count > 0)
            {
                for (int i = 0; i < dt_RawMaterialsInfo.Rows.Count; i++)
                {
                    json.AddItem("id", "X"+dt_RawMaterialsInfo.Rows[i]["id"].ToString());
                    json.AddItem("text", dt_RawMaterialsInfo.Rows[i]["Name"].ToString());
                    json.AddItem("self", "type_info");
                    json.AddItem("next", "item");
                    json.AddItem("leaf", "0");
                    json.ItemOk();
                }
                return json.ToString();
            }
            return "";
        }

        //获取原料列表
        private string GetRawMaterialList()
        {
            string RAWIDS = Request["id"];
            TreeJSONHelper json = new TreeJSONHelper();
            System.Data.DataTable dt_RawMaterialsInfo = new Catering_Rules.T_RawMaterial().GetList("RAWIDS=" + RAWIDS).Tables[0];
            if (dt_RawMaterialsInfo != null && dt_RawMaterialsInfo.Rows.Count > 0)
            {
                for (int i = 0; i < dt_RawMaterialsInfo.Rows.Count; i++)
                {
                    json.AddItem("id","I"+dt_RawMaterialsInfo.Rows[i]["id"].ToString());
                    json.AddItem("text", dt_RawMaterialsInfo.Rows[i]["RAWName"].ToString());
                    json.AddItem("self", "item");
                    json.AddItem("next", "item");
                    json.AddItem("leaf", "1");
                    json.ItemOk();
                }
                return json.ToString();
            }
            return "";
        }
    }
}